﻿package classes 
{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.display.MovieClip;
	import flash.filters.BitmapFilter;
    import flash.filters.BitmapFilterQuality;
    import flash.filters.GlowFilter;
	
	import classes.genericButton;
	import classes.showAlternativaLogo;
	import classes.loadExternalSWF;

	public class showTextHelp extends Sprite
	{
		public var sp:Sprite;
		public var helpButton:genericButton;
		
		private var instructions:TextField;
		private var instructionsFormat:TextFormat;
		private var spBackground:Sprite;
		private const boxWidth:uint = 440;
		private var btnKeyMouse:loadExternalSWF;
		private var btnWiiMote:loadExternalSWF;
		
		public function showTextHelp(_x:Number = 0, _y:Number = 0):void 
		{
			sp = new Sprite();
			
			spBackground = new Sprite();
			spBackground.graphics.beginFill(0x000000, 0.9);
			spBackground.graphics.lineStyle(1, 0x333);
			spBackground.graphics.drawRoundRect(0, 0, boxWidth, 300, 10, 10);
			spBackground.graphics.endFill();
			sp.addChild(spBackground);
			
			// Alternativa license
			var spAlternativaLogo:showAlternativaLogo = new showAlternativaLogo(2, 2); // 113x32
			spAlternativaLogo.x = spBackground.width / 2 - 113 / 2;
			sp.addChild(spAlternativaLogo);
			
			instructionsFormat = new TextFormat();
			instructionsFormat.size = 9;
			instructionsFormat.font = "Verdana";
			instructions = new TextField();
			instructions.multiline = true;
			instructions.mouseEnabled = false;
			instructions.htmlText = "<u>Instructions:</u>\n\n";
			instructions.htmlText += "Click and drag to move the camera\n\n";
			instructions.htmlText += "Hit:\n";
			instructions.htmlText += "\t<b>W A S D</b> to walk\n";
			instructions.htmlText += "\t<b>Arrows</b> to rotate the camera";
			instructions.htmlText += "\t<b>Space</b> to jump";
			instructions.htmlText += "\t<b>Enter</b> to restart the game";
			instructions.width = spBackground.width;
			instructions.height = spBackground.height;
			instructions.selectable = false;
			instructions.textColor = 0xFFFFFF;
			instructions.x = spBackground.x + 10;
			instructions.y = 32 + 10;
			instructions.setTextFormat(instructionsFormat);
			sp.addChild(instructions);
			
			btnKeyMouse = new loadExternalSWF("swf/menu/key_mouse.swf"); // 200x100
			btnWiiMote = new loadExternalSWF("swf/menu/wiiMote.swf"); // 200x100
			
			btnKeyMouse.useHandCursor = true;
			btnKeyMouse.buttonMode = true;
			btnWiiMote.useHandCursor = true;
			btnWiiMote.buttonMode = true;
			
			btnKeyMouse.addEventListener(MouseEvent.MOUSE_UP, onClickOk);
			btnKeyMouse.addEventListener(MouseEvent.MOUSE_OVER, onButtonRollOver);
			btnKeyMouse.addEventListener(MouseEvent.MOUSE_OUT, onButtonRollOut);
			//btnWiiMote.addEventListener(MouseEvent.MOUSE_UP, onClickOk);
			//btnWiiMote.addEventListener(MouseEvent.MOUSE_OVER, onButtonRollOver);
			//btnWiiMote.addEventListener(MouseEvent.MOUSE_OUT, onButtonRollOut);
			
			btnKeyMouse.x = 10;
			btnKeyMouse.y = spBackground.height - 100 - 10;
			btnWiiMote.x = spBackground.width - 200 - 10;
			btnWiiMote.y = spBackground.height - 100 - 10;
			
			btnKeyMouse.x = 10;
			btnKeyMouse.y = spBackground.height - 100 - 10
			
			btnWiiMote.x = spBackground.width - 200 - 10;
			btnWiiMote.y = spBackground.height - 100 - 10;
			btnWiiMote.enabled = false; // not available yet!
			btnWiiMote.alpha = 0.5;
			
			sp.addChild(btnKeyMouse);
			sp.addChild(btnWiiMote);
			
			//var okButton:genericButton = new genericButton("OK", 10, 80, 18);
			//okButton.x = spBackground.width / 2 - okButton.width / 2;
			//okButton.y = spBackground.height - okButton.height - 5 ;
			//okButton.addEventListener(MouseEvent.CLICK, onClickOk);
			//sp.addChild(okButton);
			
			helpButton = new genericButton("?", 10, 18, 18);
			helpButton.addEventListener(MouseEvent.CLICK, onClickHelp);
			helpButton.visible = false;
			
			addChild(sp);
			addChild(helpButton);
		}
		
		private function onButtonRollOver(e:MouseEvent):void
		{
			//GlowFilter (color:uint = 16711680, alpha:Number = 1, blurX:Number = 6, blurY:Number = 6, strength:Number = 2, quality:int = 1, inner:Boolean = false, knockout:Boolean = false);
			e.currentTarget.filters = new Array(new GlowFilter(0xFFFF00, 1, 5, 5, 2, BitmapFilterQuality.HIGH, false, false));
		}
		
		private function onButtonRollOut(e:MouseEvent):void
		{
			e.currentTarget.filters = null;
		}
		
		private function onClickOk(e:MouseEvent):void 
		{
			trace(e.currentTarget.name);
			sp.visible = false;
			helpButton.visible = true;
			helpButton.x = - helpButton.parent.x + 3;
			helpButton.y = - helpButton.parent.y + 3;
		}
		
		private function onClickHelp(e:MouseEvent):void 
		{
			sp.visible = true;
			helpButton.visible = false;
		}
		
	}

}